#!/bin/sh

set -e

if [ ! -d /etc/faktory ]; then
  mkdir /etc/faktory
  head -5 /dev/urandom | md5sum | cut -c1-16 > /etc/faktory/password
  chmod 600 /etc/faktory/password
fi

if which systemctl > /dev/null; then
  echo "Using systemd to control faktory"
  cp /usr/share/faktory/systemd/faktory.service /lib/systemd/system/faktory.service

  systemctl daemon-reload || :
  systemctl enable faktory || :
  systemctl start faktory || :
else
  echo "Couldn't find systemd to control faktory, cannot proceed."
  echo "Open an issue and tell us about your system."
  exit 1
fi

cat <<"TXT"

  __       _    _
 / _| __ _| | _| |_ ___  _ __ _   _
| |_ / _` | |/ / __/ _ \| '__| | | |
|  _| (_| |   <| || (_) | |  | |_| |
|_|  \__,_|_|\_\\__\___/|_|   \__, |
                              |___/


Welcome to Faktory, let's get working!

TXT
exit 0
